package com.scalar.chiptrack.commons.bean;

import java.util.Comparator;
import java.io.Serializable;

/**
 * User: Ganesh
  * Date: Apr 29, 2008
  * Time: 11:25:58 AM
 */

public class ResultMetaDataComparator implements Comparator, Serializable {
    public int compare( Object columnMetaData1, Object columnMetaData2 )
        {
            int result = 0;
            int order1 = Integer.parseInt( ( ( ResultMetaDataBean )columnMetaData1 ).getSortOrder() );
            int order2 = Integer.parseInt( ( ( ResultMetaDataBean )columnMetaData2 ).getSortOrder() );

            if( ! ( columnMetaData1 instanceof ResultMetaDataBean ) || !( columnMetaData2 instanceof ResultMetaDataBean ) )
            {
                throw new ClassCastException();
            }
            if( ( order1 == 0 ) && ( order2 == 0 ) )
            {
                result = 0;
            }
            else if( order1 == 0 )
            {
                result = 1;
            }
            else if( order2 == 0 )
            {
                result = -1;
            }
            else
            {
                result = order1 - order2;
            }
            return result;
        }
}
